test(desktop): deflake Command Code browser login port release - #5479
orangeCatDeveloper wants to merge 1 commit into
Conversation
isPortFree previously called occupyPort, retaining an active net.Server in netServers until afterEach rather than probing and releasing immediately. Additionally, tests completing or settling attempts (notably the simultaneous starts test) did not await the winner's loopback port release before entering the next test, leading to EADDRINUSE races where the next test skipped the closing port and unexpectedly bound a higher port number. Generated-by: GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed the current head. The only change is to apps/desktop/src/main/__tests__/commandcode-browser-login.test.ts: the port-free helper binds then closes a temporary server, and several completion paths now assert that the callback port can be rebound (:91-105,184-371). I found no substantiated P0–P3 defect in that test change.
This PR should not be merged as-is. Current main removed the Command Code GO provider and this entire test file in bd39677ec (#5545); git merge-tree reports a modify/delete conflict. The added assertions therefore exercise a feature no longer present on main. The current-head test and label checks passed and git diff --check was clean, but those do not resolve the obsolete test or merge conflict. I did not run local tests (Node 18/no installed dependencies); there is no application-code or schema/migration change. The author/maintainers should decide whether to close this PR rather than reintroduce the retired test.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
Summary
CommandCodeBrowserLoginControllertests intermittently flaked onan occupied port is skipped for the next one in the CLI rangewith46961 !== 46960. Two defects caused the port collision:isPortFreecalledoccupyPort, unintentionally retaining an activenet.ServerinnetServersuntilafterEach.two simultaneous starts) did not await the winner's loopback port release before ending, racing the subsequent test against OS socket teardown.Refs #5395
Verification
Numbers (before -> after):
netServers: 1 -> 0 (isPortFreeimmediately closes upon verifying instead of holding the port untilafterEach).two simultaneous starts: unawaited (racing) -> 100% awaited (assert.equal(await isPortFree(Number(callback.port)), true)).46961 !== 46960) -> 50/50 passed (0 failures).Checks run:
npm run format:check(biome passed)npm run lint(biome passed)npm run typecheckinapps/desktop(passed)npm run check:tui-copy(ok)node scripts/check-renderer-architecture.mjs --base origin/maininapps/desktop(passed)npm run build:mainandnode --test "dist/main/__tests__/commandcode-browser-login.test.js"inapps/desktop(20/20 passed)AI use
Select exactly one:
Tool(s) and scope: GitHub Copilot diagnosed the port race, updated probe behavior and teardown assertions, and verified test suites. Commit includes the
Generated-by: GitHub Copilottrailer.Checklist
Does this PR entail a change in behavior?